/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/crypto/hashSHA256.cpp,v 1.4 2003/11/21 12:39:24 itsme Exp $
 *
 *
 *  wrapper class around SHA256 implementation in machine\spcore\crypto.c
 *
 *  used by license verifier, keyexchange, and random number generator
 *
 *  code to verify the correct functioning of this module is in cryptoVerifier.cpp
 *
 */
#include "fnaHashFunction.h"

#include "crypto.h" // from the spcore directory

HashFunction::HashFunction()
{
    Reset();
}

HashFunction::~HashFunction()
{
    Reset();
}

ByteVector HashFunction::Calculate(const ByteVector& data)
{
    HashFunction hash;
    hash.Add(data);
    return hash.GetResult();
}

void HashFunction::Reset()
{
    crypto_sha_setup(&m_state);
}

void HashFunction::Add(const ByteVector& data)
{
    crypto_sha_add(&m_state, vectorptr(data), data.size());
}

ByteVector HashFunction::GetResult()
{
    ByteVector result(HashFunction::BLOCKSIZE);
    crypto_sha_final(&m_state, vectorptr(result), result.size());
    return result;
}



